//
//  ArticleCollectionViewCell.m
//  Style
//
//  Created by YL on 15/9/23.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#define ViewWidth(v)                        v.frame.size.width
#define ViewHeight(v)                       v.frame.size.height
#define ScreenWidth          [[UIScreen mainScreen] bounds].size.width
#define ScreenHeight         [[UIScreen mainScreen] bounds].size.height
#import "YLArticleCollectionViewCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "ArticleModel.h"
@implementation YLArticleCollectionViewCell
/* 初始化 */
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.imageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageView];
        
        self.nameView = [[UIView alloc] init];
        self.nameView.backgroundColor = [UIColor colorWithWhite:0.004 alpha:0.500];
        [self.imageView addSubview:self.nameView];
        
        self.nameLabel = [[UILabel alloc] init];
        [self.imageView addSubview:self.nameLabel];
        
        self.ennameLabel = [[UILabel alloc] init];
        [self.imageView addSubview:self.ennameLabel];
        
    }
    return self;
}

/* 布局 */
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.imageView.frame = self.contentView.frame;
    //    self.imageView.frame = self.contentView.frame;
    self.nameView.frame = CGRectMake(0, ViewHeight(self.imageView) / 6 * 5, ViewWidth(self), ViewHeight(self.imageView) / 6);
}

/* 赋值 */
- (void)setArticle_model:(ArticleModel *)article_model
{
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:article_model.coverimg] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    
    self.nameLabel.text = article_model.name;
    self.nameLabel.font = [UIFont boldSystemFontOfSize:14];
    self.nameLabel.textColor = [UIColor whiteColor];
    
    
    if ([self.nameLabel.text length] > 2) {
        self.nameLabel.frame = CGRectMake(ViewWidth(self) / 20, ViewHeight(self) / 6 * 5, ViewWidth(self) / 10 * 6, ViewHeight(self) / 6);
        self.ennameLabel.frame = CGRectMake(ViewWidth(self) / 10 * 6.5, ViewHeight(self) / 6 * 5, ViewWidth(self) / 10 * 4, ViewHeight(self) / 6);
    } else
    {
        self.nameLabel.frame = CGRectMake(ViewWidth(self) / 20, ViewHeight(self) / 6 * 5, ViewWidth(self) / 10 * 3, ViewHeight(self) / 6);
        self.ennameLabel.frame = CGRectMake(ViewWidth(self) / 10 * 4, ViewHeight(self) / 6 * 5, ViewWidth(self) / 10 * 6, ViewHeight(self) / 6);
    }
    
    if (ScreenWidth >= 375) {
        self.ennameLabel.font = [UIFont boldSystemFontOfSize:11];
    } else
    {
        self.ennameLabel.font = [UIFont boldSystemFontOfSize:10];
    }
    self.ennameLabel.text = article_model.enname;
    self.ennameLabel.textColor = [UIColor whiteColor];
}

@end
